import java.util.Stack;

public class MinStack {
    Stack<Integer> minStack;
    Stack<Integer> stack;

    public MinStack() {
       minStack =new Stack<>();
       stack=new Stack<>();
    }
    void push(int val){
        stack.push(val);
        if(minStack.isEmpty()){
            minStack.push(val);
        }else {
            if (val<=minStack.peek()){
                minStack.push(val);
            }
        }
    }
    void pop(){
        int a=stack.pop();

        if(!minStack.isEmpty()&&a==minStack.peek()){
            minStack.pop();
        }
    }
    int top(){
        return stack.peek();
    }
    int getMin(){
        if(!minStack.isEmpty()){
            return minStack.peek();
        }
        return -1;
    }

}
